package com.hoshino.momochi.service.Impl;

import com.hoshino.momochi.mapper.BlogMapper;
import com.hoshino.momochi.model.domain.Blog;
import com.hoshino.momochi.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Override
    public List<Blog> findBlogsByUser(Long uid) {
        return blogMapper.findBlogsByUser(uid);
    }

    @Override
    public List<Blog> findAllBriefBlogs() {
        return blogMapper.findAllBriefBlogs();
    }

    @Override
    public List<Blog> findPageBriefBlogs(Integer begin, Integer end) {
        return blogMapper.findPageBriefBlogs(begin, end);
    }

    @Override
    public void addUserBlog(Blog blog) {
        blogMapper.addUserBlog(blog);
    }

    @Override
    public Blog findCompleteById(Long id) {
        return blogMapper.findCompleteById(id);
    }

    @Override
    public void updateUserBlog(Blog blog) {
        blogMapper.updateUserBlog(blog);
    }

    @Override
    public void updateViews(Blog blog) {
        blogMapper.updateViews(blog);
    }

    @Override
    public void delUserBlog(Long uid, Long bid) {
        blogMapper.delUserBlog(uid, bid);
    }

    @Override
    public List<Blog> getLocalBlog(Long uid) {
        return blogMapper.getLocalBlog(uid);
    }

    @Override
    @Async
    public Future<List<Blog>> getMaxLikeBlog() {
        return new AsyncResult<>(blogMapper.getMaxLikeBlog());
    }

    @Override
    @Async
    public Future<List<Blog>> getMaxStarBlog() {
        return new AsyncResult<>(blogMapper.getMaxStarBlog());
    }

    @Override
    @Async
    public Future<List<Blog>> getMaxViewBlog() {
        return new AsyncResult<>(blogMapper.getMaxViewBlog());
    }

    @Override
    public void delIsDeleteAsTrue() {
        blogMapper.delIsDeleteAsTrue();
    }
}
